package com.pospi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pospi.dto.OrderPaytype;
import com.pospi.pai.yunpos.R;
import com.pospi.pai.yunpos.been.MsgBeen;

import java.util.List;

public class MsgAdapter extends BaseAdapter {
    private Context context;
    private List<MsgBeen> payWayDtos;

    public MsgAdapter(Context context, List<MsgBeen> payWayDtos) {
        this.context = context;
        this.payWayDtos = payWayDtos;
    }

    @Override
    public int getCount() {
        return payWayDtos.size();
    }

    @Override
    public Object getItem(int position) {
        return payWayDtos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_msg, null);
            holder = new ViewHolder();
            holder.title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.rq = (TextView) convertView.findViewById(R.id.tv_rq);
            holder.msg = (TextView) convertView.findViewById(R.id.tv_msg);
            holder.tv_status = convertView.findViewById(R.id.tv_status);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (payWayDtos.get(position).getIsread().equals("0")) {
            holder.tv_status.setVisibility(View.VISIBLE);

        } else {
            holder.tv_status.setVisibility(View.INVISIBLE);
        }
        holder.title.setText(payWayDtos.get(position).getTitle());
        holder.msg.setText(payWayDtos.get(position).getContent());
        holder.rq.setText(payWayDtos.get(position).getSendtime());
        return convertView;
    }


    class ViewHolder {
        TextView title;
        TextView rq;
        TextView msg;
        TextView tv_status;
    }

}
